package com.ruoyi.common.utils.timeBetween;

import java.time.LocalTime;
import java.util.Arrays;

public class TradeTimeUtils {

    private final TradeTimeConfig config;

    public TradeTimeUtils(TradeTimeConfig config) {
        this.config = config;
    }

    public boolean isTradeTimeNow() {
        return config.isInTradeTime(LocalTime.now());
    }

    public static TradeTimeConfig createDefaultConfig(String one, String two) {
        String[] split = one.split("-");
        String[] startTime = split[0].split(":");
        String[] endTime = split[1].split(":");
        TradeTimeConfig config = new TradeTimeConfig();
        TradeTimeConfig.TimeRange morning = new TradeTimeConfig.TimeRange();
        morning.setStart(LocalTime.of(Integer.parseInt(startTime[0]), Integer.parseInt(startTime[1])));
        morning.setEnd(LocalTime.of(Integer.parseInt(endTime[0]), Integer.parseInt(endTime[1])));
        String[] time = two.split("-");
        String[] twoStartTime = time[0].split(":");
        String[] twoEndTime = time[1].split(":");
        TradeTimeConfig.TimeRange afternoon = new TradeTimeConfig.TimeRange();
        afternoon.setStart(LocalTime.of(Integer.parseInt(twoStartTime[0]), Integer.parseInt(twoStartTime[1])));
        afternoon.setEnd(LocalTime.of(Integer.parseInt(twoEndTime[0]), Integer.parseInt(twoEndTime[1])));
        config.setTimeRanges(Arrays.asList(morning, afternoon));
        return config;
    }
}
